<?php namespace App\Admin\Card\Recharge\Listeners;

use App\Core\Exceptions\InputError;
use App\Core\Service\Listeners\CreateListener as Base;
use Input;
use DB;

class CreateListener extends Base {

    public function onCreateGeneratedData(){
        $card_id = $this->service->createData['card_id'];
        $fee = $this->service->createData['fee'];
        $this->service->createData['fee'] = $fee?$fee:0;
        if($card_id != 1){ //除微信运动外
            $cardModel = DB::table('card')->where('id','=',$card_id)->first();
            if(!$cardModel){
                throw new InputError('卡劵不存在');
                return;
            }
            $fee = $cardModel->fee;
            $this->service->createData['fee'] = $fee?$fee:0;
        }
    }
}
